package com.chixing.day09_innerclass;

import java.util.Arrays;

public class StringDemo {
    public static void main(String[] args) {
        String word = "Strings are constant; their values cannot be changed after they  are created";
//        1. 将字符串转换成 char数组
            char[] chars = word.toCharArray();
        System.out.println(Arrays.toString(chars));
//        2. 获得字符串的第一个字符，第5个字符
            char c1 = word.charAt(0);
        System.out.println(c1);
            char c2 = word.charAt(4);
        System.out.println(c2);
//        3. 判断里面是否包含 "not"
            boolean b1 = word.contains("not");
        System.out.println(b1);
//        4. 获得字符串的长度
            int a1 = word.length();
        System.out.println(a1);
//        5. 将字符串转换成 byte数组
            byte[] b = word.getBytes();
        System.out.println(Arrays.toString(b));
//        6. 获得字符串中第一次出现字母e 的下标
            int a2 = word.indexOf("e");
        System.out.println(a2);
//        7. 获得字符串中第一次出现 "an" 的下标
            int a3 = word.indexOf("an");
        System.out.println(a3);
//        8. 获得字符串中最后一次出现 "e" 的下标
            int a4 = word.lastIndexOf("e");
        System.out.println(a4);
//        9. 将字符串中的字母 'a' 替换成 'A'
            String s1 = word.replaceAll("a","A");
        System.out.println(s1);
//        10. 将字符串中的"er" 替换成 'ER'
            String s2 = word.replaceAll("er","ER");
        System.out.println(s2);
//        11. 将字符串全部转换成大写
            String s3 = word.toUpperCase();
        System.out.println(s3);
//        12. 将字符串全部转换成小写
            String s4 = word.toLowerCase();
        System.out.println(s4);
//        13. 截取前5个字符串   === 截取子字符串
            String s5 = word.substring(0,5);
        System.out.println(s5);

//        14. 截取第6-10 个字符串
            String s6 = word.substring(5,10);
        System.out.println(s6);
//        15. 截取后6 个字,符串
            String s7 = word.substring(word.length()-6);
        System.out.println(s7);
//        16. 在字符串后拼接单词"hello"
            String s8 = word.concat("hello");
        System.out.println(s8);
//        17. 获得每个单词 "Strings","are","constant;","their".....(即不输出中间的空格符号)
        System.out.println("=------------");
            String[] strings1 = word.split(" ");
        System.out.println(Arrays.toString(strings1));
//       18. 判断是否以"Str"开头
            boolean b2 = word.startsWith("Str");
        System.out.println(b2);
//        19. 判断是否以"Str"结束
            boolean b3 = word.endsWith("Str");
        System.out.println(b3);

//        20.输出原来字符串 每个字符
            String[] strings2 = word.split("");
        System.out.println(Arrays.toString(strings2));
    }
}
